//
//  KLNetWorkManager.m
//  BIBILILI
//
//  Created by 123 on 2018/8/11.
//  Copyright © 2018年 WTF. All rights reserved.
//

#import "KLNetWorkManager.h"
#import <AFNetworking.h>



@implementation KLNetWorkManager

+(instancetype)shareManager{
    static KLNetWorkManager * shareInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareInstance = [[self alloc] init];
    });
    return shareInstance;
}

- (instancetype)init
{
    if (self  = [super init]) {
     
    }
    return self;
}

-(void)requestWithURL:(NSString *)URL requestMethod:(RequestMethod)requestMethod param:(NSMutableDictionary *)Param success:(SuccessBlock)success failure:(failureBlock)failure{
    
    AFHTTPSessionManager * manager =[AFHTTPSessionManager manager];
    [self setManagerConfiguration:manager];
    
    if (requestMethod == RequestMethodGet) {
        [manager GET: URL parameters:Param progress:nil success:success failure:failure];
    }else{
       [manager POST:URL parameters:Param progress:nil success:success failure:failure];
    }
    
}
//请求头设置
-(void)setManagerConfiguration:(AFHTTPSessionManager *)manager{
    
    manager.requestSerializer = [AFJSONRequestSerializer new];
    
    [manager.requestSerializer setValue:__ApplicationID__ forHTTPHeaderField:@"X-Bmob-Application-Id"];
    [manager.requestSerializer setValue:__RestApikey__ forHTTPHeaderField:@"X-Bmob-REST-API-Key"];
    [manager.requestSerializer setValue:[UserConfig getSessionToken] forHTTPHeaderField:@"X-Bmob-Session-Token"];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
}


//-(void)isLoadInOtherDevice:(completeBlock)complete{
//    
//    NSString * m_URL = [NSString stringWithFormat:@"%@%@",__UserSessionCheckUrl__,[[UserConfig currentUser] objectId]];
//   __block BOOL tokenIsTimeOut = NO;
//    [[KLNetWorkManager shareManager] requestWithURL:m_URL requestMethod:RequestMethodGet param:[NSMutableDictionary dictionary] success:^(NSURLSessionDataTask *respones, NSDictionary *dict) {
//        if ([dict[@"msg"] isEqualToString:@"ok"]) {
//            tokenIsTimeOut = NO;
//        }
//    } failure:^(NSURLSessionDataTask *respones, NSError *error) {
//        if (!error) {
//            tokenIsTimeOut = YES;
//            
//        }
//    }];
//    
//    complete(tokenIsTimeOut);
//}

@end
